<?php
	@session_start();
	
	//--
	include "includes/configuration.php";
	include "lib/xtpl/xtemplate.class.php";
	include "lib/upload.php";
	
	//-- Set current theme
	$current_theme = 'default';
	define ( 'TEMP_PATH', ROOT_PATH . 'templates/' . $current_theme . '/' );
	
	//--
	$xtpl_main = new XTemplate ( TEMP_PATH . "layout.html" );
	$xtpl_main->assign ( "base_url", BASE_URL );
	$xtpl_main->assign ( "temp_url", BASE_URL . 'templates/' . $current_theme . '/' );
	
	//--
	$mod = ( isset ( $_GET ['mod'] ) ) ? $_GET ['mod'] : 'home';
	$act = ( isset ( $_GET ['act'] ) ) ? $_GET ['act'] : 'main';
	
	$filename = ROOT_PATH . "modules/" . $mod . "/" . $act . ".php";
	
	if ( file_exists ( $filename ) ) {
		$xtpl = new XTemplate ( ROOT_PATH . "modules/" . $mod . "/" . $act . ".html" );
		include $filename;
	} else {
		include ROOT_PATH . "modules/home/error.php";
		$xtpl = new XTemplate ( ROOT_PATH . "modules/home/error.html" );
	}
	
	$xtpl->assign ( "temp_url", BASE_URL . 'templates/' . $current_theme . '/' );
	
	//-- Get Category
	$rs_category = mysql_query("SELECT cate_id, cate_name FROM category WHERE cate_status = '1' ORDER BY cate_id ASC");
	$count_cate = mysql_num_rows($rs_category);
	if($count_cate > 0){
		$iCateCount = 1;
		while($row_category = mysql_fetch_array($rs_category)){
			if($iCateCount == 1){
				$row_category['cate_dd_class'] = 'class="first"';
			}
			if($iCateCount == $count_cate){
				$row_category['cate_dd_class'] = 'class="last"';
			}
			$iCateCount++;
			
			//--
			$row_category['cate_url'] = BASE_URL . '?cate=' . $row_category['cate_id'];
			
			//--
			$xtpl_main->assign ('list_cate', $row_category);
			$xtpl_main->parse ( "MAIN.list_cate" );
		}
	}
	
	//-- Check if member already signed in
	if(isset($_SESSION['member_id']) && $_SESSION['member_id'] != ''){
			$xtpl_main->assign ('username', $_SESSION['member_username']);
			$xtpl_main->parse("MAIN.member_panel");
	}
	
	//-- Check if admin already signed in
	if(isset($_SESSION['member_is_admin']) && $_SESSION['member_is_admin'] == '1'){
		$xtpl_main->parse("MAIN.admin_panel");
	}
	
	//--
	$xtpl->parse ( "center" );
	$xtpl_main->assign ( "center_file", $xtpl->text ( "center" ) );
	$xtpl_main->parse ( "MAIN" );
	eval ( "?" . ">" . $xtpl_main->text ( "MAIN" ) );
?>
